<template>
	<view class="page">
		<CustomNav :isBack="false" :topBgColor="topBgColor" title="我的"></CustomNav>
		<view class="user-info">
			<view class="user-photo-block">
				<!-- <view class="upload-photo-btn" @click="changeAvatar"> -->
				<view class="upload-photo-btn">
					<!-- <view class="tips">点击编辑</view> -->
					<image class="user-photo" :src="cloudStorage+user.avatar" v-if="user.avatar" mode="aspectFill">
					</image>
					<image class="user-photo"
						src="https://suzhou-taxi-1306862033.cos.ap-chengdu.myqcloud.com/file/face.png" v-else
						mode="aspectFill"></image>
				</view>
			</view>
			<view class="user-item">
				<view class="user-name">{{user.name}}</view>
				<view class="user-phone">{{user.phoneNumber}}</view>
			</view>
		</view>
		<view class="menu-block">
			<view @click="navigate('/pages/information/information')" class="menu-item">
				<image class="menu-icon" src="@/static/image/mine/mine1.png"></image>
				<view class="round"></view>
				<view class="menu-name">我的资料</view>
				<view class="iconfont icon-a-gengduo1"></view>
			</view>
			<view @click="navigate('/pages/wallet/wallet')" class="menu-item">
				<image class="menu-icon" src="@/static/image/mine/mine2.png"></image>
				<view class="round"></view>
				<view class="menu-name">收入及流水</view>
				<view class="iconfont icon-a-gengduo1"></view>
			</view>
			<view @click="navigate('/pages/settings/index')" class="menu-item">
				<image class="menu-icon" src="@/static/image/mine/setting.png"></image>
				<view class="menu-name">设置</view>
				<view class="iconfont icon-a-gengduo1"></view>
			</view>
			<view class="menu-item" @click="logout">
				<image class="menu-icon" src="@/static/image/mine/mine3.png">
				</image>
				<view class="menu-name">退出登录</view>
				<view class="iconfont icon-a-gengduo1"></view>
			</view>

		</view>
	</view>
</template>

<script>
	import {
		getUserInfoApi,
		logoutApi,
		updateDriverInfo
	} from '@/api/user.js'
	import {
		getStorage
	} from '@/util/auth.js';
	import {
		uploadFile
	} from '@/api/file.js';
	export default {
		data() {
			return {
				topBgColor: 'rgba(0,0,0,0)',
				user: {
					real_name: '',
					phone: ''
				},
				status: '',
				auditStatusStr: ''
			}
		},
		methods: {
			getUser() {
				getUserInfoApi().then((res) => {
					this.user = res;
					//this.$store.commit('user/SET_USER', res);
				});
			},
			changeAvatar() {
				let that = this
				uni.chooseImage({
					count: 1,
					success: (res) => {
						let file = res.tempFiles[0].path
						uploadFile(file).then((res) => {
							uni.showLoading({
								title: '保存中',
								mask: true
							});
							updateDriverInfo({
								avatar: res
							}).then(() => {
								that.showToast('修改成功');
								that.getUser();
							});
						});
					}
				})
			},
			logout() {
				uni.showModal({
					title: '提示',
					content: `确定要退出登录吗？`,
					confirmColor: '#3255B8',
					success: (res) => {
						if (res.confirm) {
							this.$store.dispatch('user/logout')
							uni.reLaunch({
								url: '/pages/login/login'
							})
						}
					}
				})
			},
			deleteAccount() {
				uni.showModal({
					title: '提示',
					content: '确定要注销账号吗？注销后将无法恢复，请谨慎操作！',
					confirmColor: '#EA0000',
					success: (res) => {
						if (res.confirm) {
							this.$store.dispatch('user/logout')
							uni.reLaunch({
								url: '/pages/login/login'
							})
						}
					}
				})
			}
		},
		onShow() {
			console.log(11111111111)
			console.log(getStorage('token'))
			if (getStorage('token')) {
				this.getUser()
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		overflow: hidden;
		height: 100%;

		.user-info {
			width: 100%;
			height: 400rpx;
			display: flex;
			align-items: center;
			padding: 170rpx 30rpx 30rpx 30rpx;
			background: url('/static/image/bg-img.png')no-repeat center;
			background-size: 100%;

			.user-photo-block {
				width: 140rpx;
				height: 140rpx;
				border-radius: 50%;
				overflow: hidden;

				.upload-photo-btn {
					width: 100%;
					height: 100%;
					position: relative;
					padding: 0;

					.tips {
						font-size: 20rpx;
						width: 100%;
						position: absolute;
						bottom: 0;
						left: 0;
						color: #fff;
						display: flex;
						justify-content: center;
						align-items: center;
						background: rgba(0, 0, 0, 0.5);
						z-index: 1;
						height: 48rpx;
					}
				}

				.user-photo {
					width: 100%;
					height: 100%;
					object-fit: cover;
				}

				.user-photo.ps {
					position: relative;
				}
			}

			.user-photo {
				width: 100%;
				height: 100%;
				object-fit: cover;
			}

			.user-item {
				margin-left: 30rpx;
				color: #fff;

				.user-name {
					font-size: 34rpx;
					font-weight: bold;
					margin-bottom: 20rpx;

					.user-phone {}
				}

				.authentication {
					background-color: #FAC218;
					color: #fff;
					font-size: 22rpx;
					width: 150rpx;
					height: 36rpx;
					border-radius: 6rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					margin-top: 20rpx;
				}
			}
		}

		.menu-block {
			width: $content-width;
			margin: 0 auto;
			margin-top: 30rpx;
			position: relative;

			.menu-item {
				width: 100%;
				background: #fff;
				border-radius: 8px;
				height: 130rpx;
				display: flex;
				align-items: center;
				padding: 30rpx;
				margin-bottom: 20rpx;

				.menu-icon {
					width: 40rpx;
					height: 40rpx;
					margin-right: 20rpx;
				}

				.round {
					width: 12rpx;
					height: 12rpx;
					// background-color: #EA0000;
					border-radius: 50%;
					position: absolute;
					margin-left: 30rpx;
					margin-top: -30rpx;
				}

				.menu-name {
					flex-grow: 1;
					font-size: 28rpx;
				}

				.status {
					font-size: 28rpx;
					position: absolute;
					margin-left: 200rpx;
					color: #10d269;
				}

				.iconfont {
					color: #767676;
					font-size: 28rpx;
				}
			}
		}
	}
</style>